<?php

if ($find_item[parts_left] < $find_item2[parts])
{
die("
	<br><center>
	<table width=380 cellspacing=0>
	<tr>
		<td bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Selected Item</font></b></center>
		</td>
		<td width=300 bgcolor=$topAndBottomBG>
		<center><b><font color=$topAndBottomText>Item Details</font></b></center>
	</td>
	</tr>
	<tr height=100>
	<td valign=middle>
	<p align=center><img src=images/user_images/opg_$game/items/item_$find_item2[id].gif>
	<br>
	<b>$find_item2[item_name]</b>
	</td>
	<td width=300>
	<p align=center>Sorry, your $find_item2[item_name] could not be stocked because it has already been used.<br><a href=myitems.php?game=$game>Back to your items.</a></p>
	</td>
	</tr>
	</table>
	</center>
");
}

$find_gallery = fetch("SELECT * FROM usergallerys WHERE owner = '$userid' AND game = '$game'");
$sumItems = fetch("SELECT sum(stock) AS stock FROM usergallerys_items WHERE owner = '$userid' AND game = '$game'");

if ($find_gallery[id] == "")
{
	die("You do not have a gallery yet!$closeHTML");
}

$max_stock = $find_gallery[gallery_size] * 5;

if ($sumItems[stock] >= $max_stock)
{
	die("There is not enough room for your $find_item2[item_name] in your gallery.$closeHTML");
}

$findItemIngallery = fetch("SELECT stock FROM usergallerys_items WHERE owner = '$userid' AND item_id = '$find_item2[id]' AND game = '$game'");

if ($findItemIngallery[stock])
{
	mysql_query("UPDATE usergallerys_items SET stock=$findItemIngallery[stock]+1 WHERE owner = '$userid' AND item_id = '$find_item2[id]' AND game = '$game'");
	mysql_query("DELETE FROM usersitems2 WHERE id = '$find_item[id]' AND owner = '$userid' AND game = '$game'");
	die("Your $find_item2[item_name] has been put into your gallery! (<a href=myitems.php?game=$game>back</A>)$closeHTML");
}
else
{
	mysql_query("INSERT INTO usergallerys_items (owner,item_id,stock,game) VALUES ('$userid','$find_item2[id]','1','$game')");
	mysql_query("DELETE FROM usersitems2 WHERE id = '$find_item[id]' AND owner = '$userid' AND game = '$game'");
	die("Your $find_item2[item_name] has been put into your gallery! (<a href=myitems.php?game=$game>back</A>)$closeHTML");
}

?>